<template>
	<view class="content">
		<!-- f1 图片页面 -->
		<view class="f1">
			<image :src="getImage(images)" mode=""></image>
		</view>

		<!-- f2 积分页面 -->
		<view class="f2">
			<view style="color: #6FCF97;">{{value}}
				<text style="font-size:20px; margin-left: 10rpx;color: #6FCF97;">积分</text>
			</view>
			<view style="line-height: 60rpx; font-size:20px; margin-left: 10rpx;line-height: 2rem;">{{name}}</view>
		</view>

		<!-- f3 商品服务 -->
		<view class="f3">
			<view class="left">商品服务</view>
			<view class="right">商家配送 支持自提</view>
		</view>

		<!-- f4 产品规格 -->
		<view class="f4">
			<view class="left">产品规格</view>
			<view class="right">1件</view>
		</view>

		<!-- f5 配送方式 -->
		<view class="f5">
			<view class="left">配送方式</view>
			<view class="right">
				<view style="margin-right: 30rpx;"><uni-icons style="margin-right: 10rpx;" type="checkbox"
						size="15"></uni-icons>商家配送</view>
				<view><uni-icons style="margin-right: 10rpx;" type="checkbox" size="15"></uni-icons>到店自提</view>
			</view>
		</view>

		<!-- f6 拾一块旗舰店 -->
		<view class="f6">
			<view class="left">
				<image style="margin-top: 10rpx;" src="../../static/logoimg.png" mode="heightFix"></image>
				<view style="margin-left: 10rpx;margin-top: 40rpx;">拾一块旗舰店</view>
			</view>
			<view class="right">
				<view style="border-radius: 10rpx;width: 130rpx;height: 45rpx; border: 1px solid #4F4F4F;">
					<text @click="goto('/pages/storeHomepage/storeHomepage')">门店首页</text>
				</view>
			</view>
		</view>

		<!-- 详情介绍 -->


		<!-- 底部兑换框 -->
		<view class="f8" @touchmove.stop.prevent="moveHandle">
			<view style="display: flex;">
				<view class="left" @click="goto('/pages/shopping/shopping')">
					<uni-icons type="home" size="30"></uni-icons>
					<view>首页</view>
				</view>
				<view class="right">
					<button class="btn" @click="open">立即兑换</button>
					<uni-popup ref="popup" type="bottom"></uni-popup>
					<view>
						<!-- 普通弹窗 -->
						<uni-popup ref="popup" background-color="#fff">
							<view class="popup-content"
								:class="{ 'popup-height': type === 'left' || type === 'right' }">
								<!-- 商品详情和图片 -->
								<view style="display: flex;">
									<view class="img">
										<image :src="getImage(images)" mode="widthFix"></image>
									</view>
									<view class="text">
										<text>{{name}}</text>
										<view><text>积分:{{totalPrice}}</text></view>
									</view>
								</view>
								<!-- 商品数量加减 -->
								<view class="goodsNum">
									<view class="goods_num">换购数量</view>
									<view class="goods_main">
										<view class="goods_cut" @click="goodsCut">-</view>
										<view class="goods_input">
											<input type="text" v-model.number="goodsNum">
										</view>
										<view class="goods_add" @click="goodsAdd">+</view>
									</view>
								</view>
								<view style="margin-top: 200rpx;">
									<button class="button" @click="gotoOrder">确定兑换</button>
								</view>
							</view>
						</uni-popup>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getCommodityDetail
	} from '../../common/api/product.js';
	export default {
		data() {

			return {
				value6: 0,
				type: 'center',
				// 购物车数量
				goodsNum: 1,
				user: {},
				commodityDetail: {
					id: null,
					value: null,
					description: null,
					images: null,
					commodityId: null,
					name: null,
					vip: null
				},
			}
		},
		onLoad(options) {
			const {
				id,
				name,
				description,
				value,
				images,
				vip,
				commodityId
			} = options;
			this.value = value
			this.name = name
			this.description = description
			this.images = images
			this.commodityId = commodityId
			this.id = id
			this.vip = vip
			const condition = this.$store.state.firstCondition;
			// this.category = JSON.parse(options.commodityList);
		},
		computed: {
			url() {
				return this.commodityDetail.images;
			}
		},
		mounted() {
			this.user = uni.getStorageSync('user');
		},
		methods: {
			//返回
			goToBack() {
				uni.navigateTo({
					url: '/pages/shopping/shopping'
				})
			},
			getImage(image) {
				return `http://43.136.172.73/api/v1/file/download?fileName=${image}`
			},
			goto(url) {
				uni.navigateTo({
					url: url
				})
				wx.switchTab({
					url: url
				})

			},
			open() {
				if (this.user.roleId === 2) {
					// 通过组件定义的ref调用uni-popup方法 ,如果传入参数 ，type 属性将失效 ，仅支持 ['top','left','bottom','right','center']
					this.$refs.popup.open('bottom');
				} else {
					uni.showModal({
						content: '您还不是会员，无法购买该商品，是否成为会员',
						success(res) {
							if (res.confirm) {
								// 确认按钮被点击
								uni.navigateTo({
									// 跳转到vip页面
									url: '/pages/vip/vip'
								})
							}
						}
					})
				}
			},
			goodsCut() {
				if (this.goodsNum > 1) {
					this.goodsNum -= 1
				}
			},
			goodsAdd() {
				this.goodsNum += 1
			},
			gotoOrder(options) {
				uni.navigateTo({
					url: '/pages/purchase/purchase?id=' + this.id + '&name=' + this.name + '&value=' + this.value +
						'&images=' + this.images + '&commogityId=' + this.commodityId + '&description=' + this
						.description
				})
			}
		},
		computed: {
			// 总价
			totalPrice() {
				return this.value * this.goodsNum
			},
		},
	}
</script>

<style lang="scss">
	//顶部标题
	.content-title {
		background-color: #fff;
		color: #000;
		font-weight: bold;
		height: 100rpx;
		position: relative;
		font-size: 16px;

		.title-left {
			position: absolute;
			left: 30rpx;
			top: 50%;
			transform: translate(-50%, -50%);
		}

		.title-right {
			text-align: center;
			line-height: 100rpx;
		}
	}

	.content {
		background-color: #EAEAEA;
	}

	.f1 {
		width: 100%;
		height: 700rpx;
		//防止盒子被撑大
		box-sizing: border-box;

		>image {
			border-radius: 10rpx;
			width: 100%;
			height: 100%;
		}
	}

	.f2 {
		width: 100%;
		// height: 0rpx;
		background-color: #f8f8f8;
		// margin-top: 10rpx;
		font-size: 40px;
		padding-top: 20rpx;
		padding-left: 20rpx;
	}

	.f3 {
		display: flex;
		height: 100rpx;
		margin-top: 20rpx;
		background-color: #f8f8f8;

		.left {
			font-size: 15px;
			color: #959595;
			margin-left: 20rpx;
			padding-top: 25rpx;
		}

		.right {
			font-size: 17px;
			margin-left: 50rpx;
			padding-top: 22rpx;
			color: #626167;
		}
	}

	.f4 {
		display: flex;
		background-color: #f8f8f8;
		margin-top: 30rpx;
		height: 80rpx;

		.left {
			font-size: 15px;
			color: #959595;
			margin-left: 20rpx;
			padding-top: 15rpx;
		}

		.right {
			font-size: 17px;
			margin-left: 50rpx;
			margin-top: 13rpx;
			color: #626167;
		}
	}

	.f5 {
		display: flex;
		background-color: #f8f8f8;
		margin-top: 25rpx;
		height: 80rpx;

		.left {
			font-size: 15px;
			color: #959595;
			margin-left: 20rpx;
			padding-top: 15rpx;
		}

		.right {
			display: flex;
			font-size: 17px;
			margin-left: 50rpx;
			margin-top: 13rpx;
			color: #626167;
		}
	}

	.f6 {
		display: flex;
		height: 100rpx;
		background-color: #f8f8f8;
		margin-top: 25rpx;

		.left {
			display: flex;
			font-size: 15px;
			margin-left: 20rpx;

			>image {
				// width: 150rpx;
				height: 100rpx;
				padding-top: 10rpx;
			}

			>text {
				margin-left: 15rpx;
				margin-top: 20rpx;
			}
		}

		.right {
			font-size: 15px;
			margin-left: 300rpx;
			padding-top: 30rpx;

		}
	}

	.f7 {
		background-color: #f8f8f8;
		margin-top: 10rpx;

		.xiang {
			padding-top: 80rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			font-size: 20px;
			font-weight: bold;
		}

		.img {
			margin-top: 30rpx;
			width: 100%;

			>image {
				width: 100%;
				height: 600rpx;
			}
		}


	}

	.f8 {
		width: 100%;
		position: fixed;
		bottom: 0;
		background-color: #f8f8f8;

		.left {
			width: 100rpx;
			margin-left: 20rpx;
		}

		.right {
			width: 100%;

			.btn {
				background-color: #1ca967;
				color: #f8f8f8;
			}

			.popup-content {
				padding: 50rpx;
				// height: 700rpx;
				background-color: #fff;

				.img {
					// flex: 1;
					width: 150rpx;
					// height: 50rpx;

				}

				.text {
					// flex: 1;
					margin-left: 10rpx;
					font-size: 15px;
					line-height: 50rpx;
				}

				.goodsNum {
					margin-top: 30rpx;
					display: flex;

					.goods_num {
						flex: 1;
						font-size: 20px;
					}

					.goods_main {
						display: flex;
						border: 1px solid #737373;
						width: 200rpx;

						.goods_cut {
							margin-left: 10rpx;
							font-size: 20px;
							text-align: center;
						}

						.goods_input {
							margin-left: 20rpx;
							border: 1px solid #737373;
							text-align: center;
						}

						.goods_add {
							margin-left: 10rpx;
							font-size: 20px;
							margin-right: 10rpx;
							text-align: center;
						}
					}
				}

				.button {
					background-color: #1ca967;
					border-radius: 50rpx;
					color: #f8f8f8;
				}
			}
		}
	}
</style>